home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / xvisrc.zip / MARK.C < prev    next >
C/C++ Source or Header  |  1992-07-28  |  3KB  |  145 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. #ifndef lint
  3. static char *sccsid = "@(#)mark.c    2.1 (Chris & John Downey) 7/29/92";
  4. #endif
  5.  
  6. /***
  7.  
  8. * program name:
  9.     xvi
  10. * function:
  11.     PD version of UNIX "vi" editor, with extensions.
  12. * module name:
  13.     mark.c
  14. * module function:
  15.     Routines to maintain and manipulate marks.
  16. * history:
  17.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  18.     Originally by Tim Thompson (twitch!tjt)
  19.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  20.     Heavily modified by Chris & John Downey
  21.  
  22. ***/
  23.  
  24. #include "xvi.h"
  25.  
  26. #ifdef    MEGAMAX
  27. overlay "mark"
  28. #endif
  29.  
  30. /*
  31.  * A new buffer - initialise it so there are no marks.
  32.  */
  33. void
  34. init_marks(buffer)
  35. Buffer    *buffer;
  36. {
  37.     Mark    *mlist = buffer->b_mlist;
  38.     int    i;
  39.  
  40.     for (i = 0; i < NMARKS; i++)
  41.     mlist[i].m_name = '\0';
  42.  
  43.     buffer->b_pcvalid = FALSE;
  44. }
  45.  
  46. /*
  47.  * setmark(c) - set mark 'c' at current cursor position in given buffer.
  48.  *
  49.  * Returns TRUE on success, FALSE if no room for mark or bad name given.
  50.  */
  51. bool_t
  52. setmark(c, buffer, pos)
  53. int    c;
  54. Buffer    *buffer;
  55. Posn    *pos;
  56. {
  57.     Mark    *mlist = buffer->b_mlist;
  58.     int    i;
  59.  
  60.     if (!is_alpha((unsigned char) c))
  61.     return(FALSE);
  62.  
  63.     /*
  64.      * If there is already a mark of this name, then just use the
  65.      * existing mark entry.
  66.      */
  67.     for (i = 0; i < NMARKS; i++) {
  68.     if (mlist[i].m_name == (unsigned char) c) {
  69.         mlist[i].m_pos = *pos;
  70.         return(TRUE);
  71.     }
  72.     }
  73.  
  74.     /*
  75.      * There wasn't a mark of the given name, so find a free slot
  76.      */
  77.     for (i = 0; i < NMARKS; i++) {
  78.     if (mlist[i].m_name == '\0') {    /* got a free one */
  79.         mlist[i].m_name = c;
  80.         mlist[i].m_pos = *pos;
  81.         return(TRUE);
  82.     }
  83.     }
  84.     return(FALSE);
  85. }
  86.  
  87. /*
  88.  * setpcmark() - set the previous context mark to the current position
  89.  */
  90. void
  91. setpcmark(window)
  92. Xviwin    *window;
  93. {
  94.     window->w_buffer->b_pcmark.m_pos = *(window->w_cursor);
  95.     window->w_buffer->b_pcvalid = TRUE;
  96. }
  97.  
  98. /*
  99.  * getmark(c) - find mark for char 'c' in given buffer
  100.  *
  101.  * Return pointer to Position or NULL if no such mark.
  102.  */
  103. Posn *
  104. getmark(c, buffer)
  105. int    c;
  106. Buffer    *buffer;
  107. {
  108.     Mark    *mlist = buffer->b_mlist;
  109.     int    i;
  110.  
  111.     if (c == '\'' || c == '`') {    /* previous context mark */
  112.     return(buffer->b_pcvalid ? &(buffer->b_pcmark.m_pos) : NULL);
  113.     }
  114.  
  115.     for (i = 0; i < NMARKS; i++) {
  116.     if (mlist[i].m_name == (unsigned char) c)
  117.         return(&(mlist[i].m_pos));
  118.     }
  119.     return(NULL);
  120. }
  121.  
  122. /*
  123.  * clrmark(line) - clear any marks for 'line'
  124.  *
  125.  * Used any time a line is deleted so we don't have marks pointing to
  126.  * non-existent lines.
  127.  */
  128. void
  129. clrmark(line, buffer)
  130. Line    *line;
  131. Buffer    *buffer;
  132. {
  133.     Mark    *mlist = buffer->b_mlist;
  134.     int    i;
  135.  
  136.     for (i = 0; i < NMARKS; i++) {
  137.     if (mlist[i].m_pos.p_line == line) {
  138.         mlist[i].m_name = '\0';
  139.     }
  140.     }
  141.     if (buffer->b_pcvalid && (buffer->b_pcmark.m_pos.p_line == line)) {
  142.     buffer->b_pcvalid = FALSE;
  143.     }
  144. }
  145.